package com.wkhyapp.lm.view;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wkhyapp.lm.R;
import com.wkhyapp.lm.base.SuperActivity;
import com.wkhyapp.lm.contract.PhoneLoginPresenter;
import com.wkhyapp.lm.contract.PhoneLoginView;
import com.wkhyapp.lm.http.vo.Member;
import com.wkhyapp.lm.utils.CountDownTimerUtils;
import com.wkhyapp.lm.utils.StringUtils;
import com.wkhyapp.lm.weigit.EditTextView;

import butterknife.BindView;

public class VerCodeActivity extends SuperActivity<PhoneLoginPresenter> implements PhoneLoginView {

    @BindView(R.id.yzm_et)
    EditTextView yzm_et;
    @BindView(R.id.back_iv)
    ImageView back_iv;
    @BindView(R.id.hqyzm_tv)
    TextView hqyzm_tv;
    String phone;
    @BindView(R.id.phone_tv)
    TextView phone_tv;
    @Override
    public void initUI() {
        phone = getIntent().getStringExtra("0");
        if(!StringUtils.isEmpty(phone)){
            mPresenter.getCode(phone);
            phone_tv.setText("+86 "+phone);
        }
        CountDownTimerUtils countDownTimerUtils = new CountDownTimerUtils(hqyzm_tv,60000,1000);
        countDownTimerUtils.start();
    }


    @Override
    protected void initListener() {
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        yzm_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            //输入时的调用
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                Log.d(TAG, "onTextChanged() returned: "+charSequence.toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {
                if(editable.length()>=6){
                    showLoad("正在校验");
                   mPresenter.codeVer(phone,editable.toString());
                }
            }
        });

        hqyzm_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }


    @Override
    public void loginSucc(Member member) {

    }


    @Override
    public void loginFial(String str) {
        TToast(str);
    }
    @Override
    public void getCode(String str) {


    }

    @Override
    public void verSucc(String str) {
        TToast("验证成功");
        goTo(UpdatePwdActivity.class,phone);
        finish();
    }


    @Override
    protected PhoneLoginPresenter createPresenter() {
        return mPresenter = new PhoneLoginPresenter(this);
    }


    @Override
    protected void afterCreate() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_ver_code;
    }


}
